package com.tshopping.controller;

import com.tshopping.bean.Address;
import com.tshopping.service.AddressService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @name: AddressController
 * @description: 地址页面控制器
 * @author: Jackeys
 * @date: 2020-12-24 20:59
 */
@RestController
@RequestMapping("/AddressController")
@CrossOrigin
public class AddressController {
    @Autowired
    private AddressService addressService;

    @PostMapping(value = "/addAddress")
    /**
     * @description 添加用户地址
     * @Param: name
     * @Param: phone
     * @Param: address
     * @Param: user
     * @Param: province
     * @Param: city
     * @Param: district
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-24 21:31
     */
    public ResponseData addAddress(String name, String phone, String address, int user, String province, String city, String district) {
        return addressService.addAddress(name, phone, address, user, province, city, district);
    }

    @PostMapping(value = "/getUserAddresses")
    /**
     * @description 返回用户地址集合
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-24 21:31
     */
    public ResponseData getUserAddresses(int user) {
        return addressService.getUserAddresses(user);
    }

    @PostMapping(value = "/updateAddress")
    /**
     * @description 修改用户地址
     * @Param: name
     * @Param: phone
     * @Param: address
     * @Param: province
     * @Param: city
     * @Param: district
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-25 12:32
     */
    public ResponseData updateAddress(String name, String phone, String address, String province, String city, String district, int id) {
        return addressService.updateAddress(name, phone, address, province, city, district, id);
    }

    @PostMapping(value = "/updateDefault")
    /**
     * @description 修改用户默认地址
     * @Param: newId
     * @Param: oldId
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-25 18:08
     */
    public ResponseData updateDefault(int newId, int oldId) {
        return addressService.updateDefault(newId, oldId);
    }

    @PostMapping(value = "/addDefault")
    /**
     * @description 添加用户默认
     * @Param: newId
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-25 20:01
     */
    public ResponseData addDefault(int newId) {
        return addressService.addDefault(newId);
    }

    @PostMapping(value = "/deleteAddress")
    /**
     * @description 删除用户地址
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2020-12-25 18:48
     */
    public ResponseData deleteAddress(int id) {
        return addressService.deleteAddress(id);
    }

    @PostMapping(value = "/getDefaultAddress")
    /**
     * @description 处理用户默认地址
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 20:38
     */
    public ResponseData getDefaultAddress(int user){
        return addressService.selectDefault(user);
    }
}
